package com.dongdongmovie.controller;

import com.dongdongmovie.pojo.TabCategory;
import com.dongdongmovie.service.TabCategory_Service;
import com.dongdongmovie.util.RedisPermissionConstant;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("TabCategory")
public class TabCategory_Controller {

    //注入service
    @DubboReference
    private TabCategory_Service tabCategory_service;
    @Autowired
    private RedisTemplate redisTemplate;

    //跳转到show
    @RequestMapping("tzshow")
    public String tzshow() {
        return "TabCategory/show";
    }

    //跳转到add
    @RequestMapping("tzadd")
    public String tzadd() {
        return "TabCategory/add";
    }

    //跳转到update
    @RequestMapping("tzupdate")
    public String tzupdate(Integer cid, Model m) {
        TabCategory t = tabCategory_service.showbyId(cid);
        m.addAttribute("t", t);
        return "TabCategory/update";
    }

    //查询全部
    @ResponseBody
    @RequestMapping("show")
    public List<TabCategory> show() {
        return tabCategory_service.show();
    }

    //添加数据
    @ResponseBody
    @RequestMapping("add")
    public int add(TabCategory t) {
        redisTemplate.delete(RedisPermissionConstant.PERMISSION);
        return tabCategory_service.add(t);
    }

    //修改数据
    @ResponseBody
    @RequestMapping("update")
    public int update(TabCategory t) {
        redisTemplate.delete(RedisPermissionConstant.PERMISSION);
        return tabCategory_service.update(t);
    }

    //根据id删除数据
    @ResponseBody
    @RequestMapping("delete")
    public int delete(Integer cid) {
        redisTemplate.delete(RedisPermissionConstant.PERMISSION);
        return tabCategory_service.deletebyId(cid);
    }

    //批量删除数据
    @ResponseBody
    @RequestMapping("deleteall")
    public int deleteall(@RequestParam(value = "cids[]") Integer[] cids) {
        redisTemplate.delete(RedisPermissionConstant.PERMISSION);
        return tabCategory_service.deleteall(cids);
    }

    //向上移动
    @ResponseBody
    @RequestMapping("goup")
    public int goup(Integer cid) {
        redisTemplate.delete(RedisPermissionConstant.PERMISSION);
        return tabCategory_service.updategoup(cid);
    }

    //向下移动
    @ResponseBody
    @RequestMapping("decline")
    public int decline(Integer cid) {
        redisTemplate.delete(RedisPermissionConstant.PERMISSION);
        return tabCategory_service.updatedecline(cid);
    }
}
